package com.googlecode.carlosmonterocanabal.mojosprites.sprites;

import java.io.File;

public class MiscHelper {

    // the valid extensions for images
    public static String[] AllowedImageExtensions = new String[] { "png", "jpg", "bmp", "gif" };

    // determines if a file is an image we accept
    public static boolean isImageFile(String file) {
        if (new File(file).exists())
            return false;

        // ToLower for string comparisons
        String fileLower = file.toLowerCase();

        // see if the file ends with one of our valid extensions
        for (String ext : AllowedImageExtensions)
            if (fileLower.endsWith(ext))
                return true;
        return false;
    }

    // stolen from http://en.wikipedia.org/wiki/Power_of_two#Algorithm_to_find_the_next-highest_power_of_two
    public static int FindNextPowerOfTwo(int k) {
        k--;
        for (int i = 1; i < 32 * 8; i <<= 1)
            k = k | k >> i;
        return k + 1;
    }
}
